package com.java.controller.admin;

import com.java.entity.Admin;
import com.java.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/api/vue-admin-template/admin")
public class AdminController {

   @Autowired
    private AdminService adminService;

   @RequestMapping("/login")
   @ResponseBody
   public Map<String,Object> login(@RequestBody @RequestParam("username") String aName,
                                   @RequestBody @RequestParam("password") String pwd){
       Admin login = adminService.login(aName, pwd);
       Map<String,Object> map=new HashMap<>();
       if (login!=null){
           map.put("data",login);
           map.put("code",20000);
           map.put("message","用户登录成功");
       }else {
           map.put("data","");
           map.put("code",20001);
           map.put("message","用户登录失败,请检查密码或用户名是否输入正确");
       }
       return map;
   }

    //info生成令牌
    @GetMapping("/info")
    public Map<String,Object> info(){
       Map<String,Object> map=new HashMap<>();
       Map<String,Object> map2=new HashMap<>();

        map2.put("roles","admin");
        map.put("code",20000);
        map.put("success","成功");
        map2.put("name", "admin");
        map2.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        map.put("data",map2);
        return map;
    }

    //用户退出
    @PostMapping("/logout")
    public Map<String,Object> logout(){
        Map<String,Object> map=new HashMap<>();
        Map<String,Object> map2=new HashMap<>();

        map2.put("roles","admin");
        map.put("code",20000);
        map.put("success","成功");
        map2.put("name", "admin");
        map2.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        map.put("data",map2);
        return map;
    }
}